package com.atguigu.gmall.mq.reveiver;

import com.atguigu.gmall.mq.config.DeadLetterMqConfig;
import com.rabbitmq.client.Channel;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * @author: atguigu
 * @create: 2023-05-09 10:24
 */
@Slf4j
@Component
public class DeadLetterReceiver {

    /**
     * 死信消息消费者
     * @param msg
     * @param channel
     * @param message
     */
    @SneakyThrows
    @RabbitListener(queues = {DeadLetterMqConfig.queue_dead_2})
    public void deadLetterMsg(String msg, Channel channel, Message message) {
        if (StringUtils.isNotBlank(msg)) {
            log.info("死信消息监听器,监听消息:{}", msg);
        }
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
    }
}
